/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.metasploit.framework;

import org.jruby.RubyObject;
import org.jruby.RubyArray;

/**
 *
 * @author hughneale
 */
public class Exploit extends Module {

    // @TODO should be dealt with in the DataStore
    private Options opts;

    //Do enums at another time
    //public static enum Check {SAFE, DETECTED, APPEARS, VULNERABLE, UNSUPPORTED};

    public static final int SAFE = 0;
    public static final int DETECTED = 1;
    public static final int APPEARS = 2;
    public static final int VULNERABLE = 3;
    public static final int UNSUPPORTED = 4;

    public Exploit(Framework fw, RubyObject m) {
        super(fw, m);
    }

    public Options getOptions() {
        return this.opts;
    }

    @Override
    public void set(String key, Object value) {
        if(opts == null) {
            opts = new Options(this.self().getRuntime());
        }
        opts.add(key, value);
    }

    public long check() {

        Object chk =  this.getFramework().invoke(this.self(), "check");

        if(chk instanceof RubyArray) {
            return (Long)((RubyArray) chk).get(0);
        }

        return -1;
        
    }

    public Exploit New() {
        RubyObject o = (RubyObject) this.getFramework().invoke(this.self(), "new");
        //System.out.println(o.getClass().getCanonicalName());
        return new Exploit(this.getFramework(), o);
    }

}
